package net.dodoman;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReadAndWrite {
	private static final String FILE_NAME = "E:\\Work\\javapro\\src\\net\\dodoman\\test.txt";

	private static final String FILE_NAME_OHTER = "E:\\Work\\javapro\\src\\net\\dodoman\\test1.txt";

	public File createNewFile(String name) {
		File file = new File("." + name);
		return file;
	}

	public String readFile(String fileName) throws IOException {
		File file = new File(fileName);
		StringBuffer sb = new StringBuffer();
		String s;
		FileReader fr = new FileReader(file);
		BufferedReader br = new BufferedReader(fr);
		while ((s = br.readLine()) != null) {
			sb.append(s);
			sb.append("\n");
		}
		return sb.toString();
	}

	public void writeFile(String fileName, String string) throws IOException {
		File file = new File(fileName);
		FileWriter fw = new FileWriter(file);
		BufferedWriter bw = new BufferedWriter(fw);
		bw.write(string);
		bw.close();
	}

	public static void main(String args[]) throws IOException {
		String string;
		ReadAndWrite readAndWrite = new ReadAndWrite();
		string = readAndWrite.readFile(FILE_NAME);
		System.out.println(string);
		readAndWrite.writeFile(FILE_NAME, "bbbbb");
		string = readAndWrite.readFile(FILE_NAME);
		System.out.println(string);
	}
}
